package patrol.mobile.com.mobilepatrol.manager;

import java.util.List;

import io.realm.Realm;
import io.realm.RealmResults;
import patrol.mobile.com.mobilepatrol.PatrolApp;
import patrol.mobile.com.mobilepatrol.bean.Route;

import static patrol.mobile.com.mobilepatrol.PatrolApp.realm;

/**
 * Created by apple on 17/11/20.
 */

public class RouteManager {
    public static void delAllRoutes(){
        realm.executeTransaction(new Realm.Transaction() {
            @Override
            public void execute(Realm realm) {
                realm.delete(Route.class);
            }
        });
    }
    public static List<Route> getAllRoutes(){
        return realm.where(Route.class).equalTo("org_No",UserManager.getOrgNo()).findAll();
    }
    public static boolean isNull(){
        if (getAllRoutes().size()>0){
            return false;
        }else{
            return true;
        }
    }
    public static Route getFirstRoute(){
        return realm.where(Route.class).equalTo("org_No",UserManager.getOrgNo()).findFirst();
    }

    public static Route getRoute(String id){
       RealmResults<Route> results =  PatrolApp.realm.where(Route.class).equalTo("manageID",id).findAll();
        return results.get(0);
    }

}
